package cn.edu.ctbu.lablist.service.impl;

import cn.edu.ctbu.lablist.domain.Student;
import cn.edu.ctbu.lablist.domain.Teacher;
import cn.edu.ctbu.lablist.repository.TeacherRepository;
import cn.edu.ctbu.lablist.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherimplService implements TeacherService {

    @Autowired
    private TeacherRepository teacherRepository;


    public List<Teacher> findAll(){
        return teacherRepository.findAll();
    }
    /**
     * 只分页的查询
     *
     * @param pageable
     * @return
     */
    public Page<Teacher> findAll(Pageable pageable){
        return teacherRepository.findAll(pageable);
    }
    /**
     *分页，带过滤的查询
     * @param teacher
     * @param pageable
     * @return
     */
    public Page<Teacher> findAll(Example<Teacher> teacher, Pageable pageable){
        return teacherRepository.findAll(teacher,pageable);
    }
    /**
     * 按id进行查询
     * @param id 主键，整数
     * @return
     */
    public Teacher findById(Integer id){
        return teacherRepository.findById(id).orElse(null);
    }

    /**
     * 按名字进行查询,Like
     * @param name 字符串
     * @return
     */
    public List<Teacher> findByName(String name){


        return teacherRepository.findByNameLike(name);
    }

    /**
     * 按名字和密码查询
     * @param name
     * @param password
     * @return
     */
    public List<Teacher> findByNameAndPassword(String name,String password){

        return teacherRepository.findByNameAndPassword(name,password);
    }
    /**
     * 按教师编号和密码查询
     * @param no
     * @param password
     * @return
     */
    public List<Teacher> findByNoAndPassword(String no,String password){

        return teacherRepository.findByNoAndPassword(no,password);
    }
    /**
     * 创建
     * @param teacher
     */
    public void insert(Teacher teacher){
        teacherRepository.save(teacher);
    }

    /**
     * 更新
     * @param teacher
     */
    public void update(Teacher teacher){
        teacherRepository.save(teacher);
    }

    /**
     * 删除
     * @param id
     */
    public void delete(Integer id){
        teacherRepository.deleteById(id);
    }
/*
    public List<Teacher> findByYear(String year){

        return teacherRepository.findByYear(year);
    }*/

    /**
     * 按工号查找,Like
     * @param no
     * @return
     */
    public Teacher findByNo(String no){


        return teacherRepository.findByNoLike(no);
    }

}